package com.woniuxy.order.config;

import com.woniuxy.order.entity.dto.DocDto;
import org.checkerframework.checker.units.qual.Prefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableConfigurationProperties(DocDto.class)
public class Swagger2Config {
    @Autowired
    private DocDto docDto;


    @Bean
    public Docket createDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.apiInfo(new ApiInfoBuilder().title(docDto.getTitle()).description(docDto.getDesc())
                .contact(new Contact(docDto.getAuthor().getName(), docDto.getAuthor().getUrl(), docDto.getAuthor().getEmail()))
                .build()).select().apis(RequestHandlerSelectors.basePackage(docDto.getBasePath()))
                .paths(PathSelectors.any())
                .build();
        return docket;


    }


}
